<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require '../com.swiss.mooh.dao.impl/DescriptionDaoImpl.php';
require '../com.swiss.mooh.service/DescriptionServiceImpl.php';
require '../com.swiss.mooh.model/Description.php';

$dispatcher = new DescriptionDaoImpl();
$descService = new DescriptionServiceImpl($dispatcher);

switch ($_POST['type']) {
    case 99:
        $menuID = $_POST['menuID'];
        $resultList = $descService->getAllDescriptionByMenuID($menuID);
        ?>
        <div class = "table-responsive">
            <table class = "table table-bordered table-hover table-striped">
                <thead>
                    <tr>
                        <th>No.</th>
                        <th>Menu Name</th>
                        <th>Create Date time</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if ($resultList->Size() < 1) {
                        ?>
                        <tr>
                            <td colspan="4" align="center">No data found</td>
                        </tr>
                        <?php
                    } else {
                        for ($i = 0; $i < $resultList->Size(); $i++) {
                            $resultVO = $resultList->GetObj($i);
                            ?>
                            <tr>
                                <td><?= $i + 1 ?></td>
                                <td><?= $resultVO->getDescName(); ?></td>
                                <td><?= $resultVO->getDescCreatedDateTime(); ?></td>
                                <td><input type="button" onclick="getDescriptionByID('<?= $resultVO->getDescID(); ?>', '<?= $menuID ?>')" class="btn btn-xs btn-primary" value="Edit"/>
                                    <input type="button" onclick="deleteDesriptionByID('<?= $resultVO->getDescID(); ?>', '<?= $menuID ?>')" class="btn btn-xs btn-danger" value="Delete"/></td>
                            </tr>
                            <?php
                        }
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <?php
        break;
}
